const state = {
  goodsNum: 0
}
const mutations = {
  // 设置goodNum的值
  setNum: state => {
    let cartList = JSON.parse(localStorage.getItem('cartList') || '[]')
    let total = 0
    cartList.map(item => {
      total += item.num
    })
    state.goodsNum = total
  },
  // 添加至购物车，更改goodsNum
  addToCart: state => {
    state.goodsNum += 1
  }
}
const actions = {}
const getters = {}
export default {
  state,
  mutations,
  actions,
  getters
}
